import { parse } from 'querystring';
import pathRegexp from 'path-to-regexp';

/* eslint no-useless-escape:0 import/prefer-default-export:0 */
const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/;
export const isUrl = (path) => reg.test(path);

export const getContextPath = () => {
  let path = window.location.href;
  let hashIndex = path.indexOf("#")
  if (hashIndex > 0) {
    return path.substr(0,hashIndex+1)
  }
  return window.location.origin;
}

export const getPageQuery = () => parse(window.location.href.split('?')[1]);

